** Replication
** ``Doi Moi and Vietnamese Threat Perception of China''
** Byunghwan Son (bson3@gmu.edu)

* This do-file replicates all the estimtes in the main text.
* Unless otherwise specified, the models here refer to those reported in Table 1.


log using jjps, replace
**********************************************
* globals (change this according to your own working directory configuration)
 global dir "PUT IN THE PATH TO YOUR WORKING DIRECTORY HERE"

 /*
 ** data files that sould be in this working directory
	- jjps.dta
	- pew2017_indo.dta
	- pew2017_phil.dta
	- vietnam2014_jjps.dta
	- fav.dta
 */
********************************************** 
cd "$dir"

* model 1: benchmark
use jjps, clear

rdrobust ChEcon birth, kernel(tri) bwselect(mserd) c(1983) ///
	covs(income urban)  

	* Figure 3
	rdplot ChEcon birth if birth>1949 /*just to make it less ugly */, kernel(tri) bwselect(mserd) /// 
	shade ci(95) graph_options(legend(off) xtitle("cut=born in 1983")) c(1983)
	gr export rdd.eps, replace	
	
* model 2: 	CERRD
use jjps, clear

rdrobust ChEcon birth, kernel(tri) bwselect(cerrd) c(1983) ///
	covs(income urban)  	
			
* model 3: Local Randomization
use jjps, clear

	** density test
		* rddensity birth, c(1983)
	** falsification analysis
		* rdwinselect birth, c(1983) nwindows(1) 
rdrandinf ChEcon birth, seed(100) wl(1982) wr(1984) c(1983) interfci(.05)

* model 4: Fuzzy RD
use jjps, clear

rdrobust ChEcon x, kernel(tri) bwselect(mserd) ///
		covs(urban income) fuzzy(frd) 	
		
* model 5: Indonesia
use pew2017_indo, clear

	gen income = d_income_indonesia
	recode income 98=. 99=.

	rdrobust ChEcon birth, kernel(tri) bwselect(mserd) c(1983) ///
	covs(income urban)

* model 6: The Philippines	
use pew2017_phil, clear
	
	gen income = d_income_philippines
	recode income 98=. 99=.

	rdrobust ChEcon birth, kernel(tri) bwselect(mserd) c(1983) ///
	covs(income urban)	

* model 7: Vietnam 2014 data
cd "$dir"
use vietnam2014_jjps, clear

gen income = Q149VIE
recode income 98=. 99=.

gen urban = Q180VIE

rdrobust ChEcon birth, 	/// 
	c(1983) kernel(tri) bwselect(mserd) covs(income urban)

* model 8: favorability
use fav, clear

rdrobust china birth, kernel(tri) bwselect(mserd) c(1983) ///
	covs(income urban)

* model 9: 	composite index
use jjps, clear

rdrobust add_ch birth3, /// 
	kernel(tri) bwselect(mserd) c(1983) covs(income urban) 	

* model 10: Russia
use jjps, clear

rdrobust russia birth, kernel(tri) bwselect(mserd) c(1983) ///
	covs(income urban)	

	
* Figure 4. Placebo
use jjps, clear

gen beta = .
gen lo = .
gen hi = .

forvalues i=1979(1)1987	{
rdrobust ChEcon birth, c(`i') kernel(tri) bwselect(mserd)  ///
	covs(urban male)  	
	
replace beta = e(tau_cl) if birth==`i'
	replace lo = e(ci_l_rb) if birth==`i'
	replace hi = e(ci_r_rb) if birth==`i'
		
}	
	*

forvalues i= 1(1)3 {
gen beta`i'=.
gen lo`i'=.
gen hi`i'=.

}
*
	
forvalues i=1979(1)1982 	{
rdrobust ChEcon birth, c(`i') kernel(tri) bwselect(mserd)  ///
	covs(urban male)  	
	
replace beta1 = e(tau_cl) if birth==`i'
	replace lo1 = e(ci_l_rb) if birth==`i'
	replace hi1 = e(ci_r_rb) if birth==`i'
		
}	
*

rdrobust ChEcon birth, c(1983) kernel(tri) bwselect(mserd)  ///
	covs(urban male)  	
	
replace beta2 = e(tau_cl) if birth==1983
	replace lo2 = e(ci_l_rb) if birth==1983
	replace hi2 = e(ci_r_rb) if birth==1983

*
forvalues i=1984(1)1987 	{
rdrobust ChEcon birth, c(`i') kernel(tri) bwselect(mserd)  ///
	covs(urban male)  	
	
replace beta3 = e(tau_cl) if birth==`i'
	replace lo3 = e(ci_l_rb) if birth==`i'
	replace hi3 = e(ci_r_rb) if birth==`i'
		
}	
*
	

twoway (rcap hi1 lo1 birth, lc(black)) /// 
	(rcap hi2 lo2 birth, lc(red) lw(thick)) ///
	(rcap hi3 lo3 birth, lc(black)) /// 
	(scatter beta birth, m(O) msize(vlarge) mlc(black) mfc(black)) ///
	(scatter beta2 birth, m(O) msize(vlarge) mlc(red) mfc(red)) ///
	(line y0 birth, lp(dash) lc(red)) if birth>1978 & birth<1988, /// 
	xtitle(Birth Year Cutoff) legend(off) ytitle("") xlabel(1979 1983 1987)
	
gr export placebo_viet.eps, replace
	
log close
* end of the file	
			
